package com.ship.dispatch.bean.orderPay;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.BaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.enums.CurrencyStatus;
import com.ship.common.core.enums.OrderStatus;
import com.ship.common.core.enums.OrderType;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import com.ship.dispatch.util.NumberFormatUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 资金管理表（支付结算中）
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sp_fund_manage")
public class SpFundManage extends BaseBean implements Joinable {
    /**
     * 订单编号
     */
    @Label(value="订单编号")
    @SearchItem
    @TableColumn
    @TableField("pay_order_number")
    @ApiModelProperty(value = "订单编号")
    private String payOrderNumber;

    /**
     * 订单类型
     */
    @Label(value="订单类型",enumContent = "支付结算订单类型")
    @SearchItem
    @TableField("order_type")
    @ApiModelProperty(value = "订单类型")
    private Integer orderType;

    /**
     *订单类型字符串
     */
    @Label(value="订单类型")
    @TableColumn
    @TableField(exist = false)
    @ApiModelProperty(value = "订单类型字符串")
    private String orderTypeStr;

    /**
     * 航次号
     */
    @Label(value="航次号")
    @SearchItem
    @TableColumn
    @TableField("voyage_no")
    @ApiModelProperty(value = "航次号")
    private String voyageNo;

    /**
     * 船舶名称
     */
    @TableField("ship_name")
    private String shipName;
    /**
     * 预计装载时间
     */
    @TableField("expected_loading_date")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedLoadingDate;
    /**
     * 预计卸载时间
     */
    @TableField("expected_unloading_date")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expectedUnloadingDate;
    /**
     * 预计装载港
     */
    @TableField("expected_loading_port")
    private String expectedLoadingPort;
    /**
     * 预计卸载港
     */
    @TableField("expected_unloading_port")
    private String expectedUnloadingPort;

    /**
     * 支付金额
     */
    @Label(value="支付金额")
    @SearchItem
    @TableField("pay_amount")
    @ApiModelProperty(value = "支付金额")
    private BigDecimal payAmount;

    @Label(value="支付金额")
    @TableColumn
    @TableField(exist = false)
    private String payAmountStr;

    /**
     * 支付金额单位（1：美元、2：欧元、3：人民币）
     */
    @Label(value="支付金额单位")
    @TableField("pay_amount_unit")
    @ApiModelProperty(value = "支付金额单位（1：美元、2：欧元、3：人民币）")
    private Integer payAmountUnit;

    @TableField(exist = false)
    private String payAmountUnitStr;

    /**
     * 账户余额（更新）
     */
    @Label(value="账户余额·更新")
    @SearchItem
    @TableField("account_balance")
    @ApiModelProperty(value = "账户余额（更新）")
    private BigDecimal accountBalance;

    @Label(value="账户余额·更新")
    @TableColumn
    @TableField(exist = false)
    private String accountBalanceStr;

    /**
     * 实付金额
     */
    @Label(value="实付金额")
    @SearchItem
    @TableField("paid_amount")
    @ApiModelProperty(value = "实付金额")
    private BigDecimal paidAmount;

    @Label(value="实付金额")
    @TableColumn
    @TableField(exist = false)
    private String paidAmountStr;

    /**
     * 支付时间
     */
    @Label(value="支付时间")
    @TableField("pay_end_time")
    @ApiModelProperty(value = "支付时间")
    private Date payEndTime;

    @Label(value="支付时间")
    @TableColumn
    @TableField(exist = false)
    @ApiModelProperty(value = "支付时间str")
    private String payEndTimeStr;

    /**
     * 申请人
     */
    @Label(value="申请人")
    @SearchItem
    @TableColumn
    @TableField("applicant_people")
    @ApiModelProperty(value = "申请人")
    private String applicantPeople;

    /**
     * 经办人
     */
    @Label(value="经办人")
    @SearchItem
    @TableColumn
    @TableField("handle_people")
    @ApiModelProperty(value = "经办人")
    private String handlePeople;

    /**
     * 审批人
     */
    @Label(value="审批人")
    @SearchItem
    @TableColumn
    @TableField("approved_people")
    @ApiModelProperty(value = "审批人")
    private String approvedPeople;

    /**
     * 备注
     */
    @Label(value="备注")
    @SearchItem
    @TableColumn
    @TableField("order_remark")
    @ApiModelProperty(value = "备注")
    private String orderRemark;

    /**
     * 初始账户余额
     */
    @Label(value="账户余额·初始")
    @SearchItem
    @TableField("account_initial_balance")
    @ApiModelProperty(value = "初始账户余额")
    private BigDecimal accountInitialBalance;

    @Label(value="账户余额·初始")
    @TableColumn
    @TableField(exist = false)
    private String accountInitialBalanceStr;

    /**
     * 订单状态（1：未审核、2：已审核、3：已付款）
     */
    @Label(value="订单状态")
    @TableField("order_status")
    @SearchItem
//    @TableColumn
    @ApiModelProperty(value = "订单状态（1：未审核、2：已审核、3：已付款）")
    private Integer orderStatus;

    @TableField(exist = false)
    private String orderStatusListForSearch;

    /**
     *订单状态字符串
     */
    @Label(value="订单状态")
    @TableField(exist = false)
    @SearchItem
    @TableColumn
    private String orderStatusStr;



    /**
     * 第几次
     */
    @TableField("voyage_number")
    @ApiModelProperty(value = "第几次")
    private Integer voyageNumber;

    /**
     * 公司名称
     */
    @Label(value="公司名称")
    @TableField(exist = false)
    @ApiModelProperty(value = "公司名称")
    private String corporateName;

    /**
     * 备注
     */
    @Label(value="原因")
    @SearchItem
    @TableColumn
    @ApiModelProperty(value = "备注（余额变更）")
    private String accountEditBalanceRemark;

    /**
     * 文件地址
     */
    @Label(value="余额变更文件地址")
    @ApiModelProperty(value = "文件地址（余额变更）")
    private String accountEditBalancePath;

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }

    public String getAccountInitialBalanceStr() {
        String result = null;
        if (getAccountInitialBalance() != null) {
            result = NumberFormatUtil.numericFormatting(accountInitialBalance)+getPayAmountUnitStr();
        }
        return result;
    }

    public String getPayAmountUnitStr() {
        String result = "美元";
        if (getPayAmountUnit() != null) {
            if (payAmountUnit.equals(CurrencyStatus.DOLLAR.getCode())) {
                result = CurrencyStatus.DOLLAR.getInfo();
            } else if (payAmountUnit.equals(CurrencyStatus.EURO.getCode())) {
                result = CurrencyStatus.EURO.getInfo();
            } else if (payAmountUnit.equals(CurrencyStatus.RMB.getCode())) {
                result = CurrencyStatus.RMB.getInfo();
            }
        }
        return result;
    }

    public String getPaidAmountStr() {
        String result = null;
        if (getPaidAmount() != null) {
            result = NumberFormatUtil.numericFormatting(paidAmount)+getPayAmountUnitStr();
        }
        return result;
    }

    public String getAccountBalanceStr() {
        String result = null;
        if (getAccountBalance() != null) {
            result = NumberFormatUtil.numericFormatting(accountBalance)+getPayAmountUnitStr();
        }
        return result;
    }

    public String getPayAmountStr() {
        String result = null;
        if (getPayAmount() != null) {
            result = NumberFormatUtil.numericFormatting(payAmount)+getPayAmountUnitStr();
        }
        return result;
    }

    public String getPayEndTimeStr() {
        Date now = getPayEndTime();
        if (now != null) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
            return formatter.format(now);
        } else {
            return ""; // 或者返回其他默认值，视情况而定
        }
    }

    public String getOrderTypeStr(){
        String result = null;
        if (getOrderType()!=null) {
            if(orderType.equals(OrderType.LOADING_PORT_PAY.getCode())){
                result = OrderType.LOADING_PORT_PAY.getInfo();
            }else if(orderType.equals(OrderType.LOADING_PORT_PAY_END.getCode())){
                result = OrderType.LOADING_PORT_PAY_END.getInfo();
            }else if(orderType.equals(OrderType.UNLOADING_PORT_PAY.getCode())){
                result = OrderType.UNLOADING_PORT_PAY.getInfo();
            }else if(orderType.equals(OrderType.UNLOADING_PORT_PAY_END.getCode())){
                result = OrderType.UNLOADING_PORT_PAY_END.getInfo();
            }else if(orderType.equals(OrderType.CHARTERER_INSURANCE.getCode())){
                result = OrderType.CHARTERER_INSURANCE.getInfo();
            }else if(orderType.equals(OrderType.CARGO_INSURANCE.getCode())){
                result = OrderType.CARGO_INSURANCE.getInfo();
            }else if(orderType.equals(OrderType.LOADING_PORT_THIRD_PARTY.getCode())){
                result = OrderType.LOADING_PORT_THIRD_PARTY.getInfo();
            }else if(orderType.equals(OrderType.UNLOADING_PORT_THIRD_PARTY.getCode())){
                result = OrderType.UNLOADING_PORT_THIRD_PARTY.getInfo();
            }else if(orderType.equals(OrderType.SHIP_RENTAL.getCode())){
                result = OrderType.SHIP_RENTAL.getInfo();
            }else if(orderType.equals(OrderType.SHIP_NEXT_RENTAL.getCode())){
                result = OrderType.SHIP_NEXT_RENTAL.getInfo();
            }else if(orderType.equals(OrderType.SHIP_END_RENTAL.getCode())){
                result = OrderType.SHIP_END_RENTAL.getInfo();
            }else if(orderType.equals(OrderType.DELIVERY_FEE.getCode())){
                result = OrderType.DELIVERY_FEE.getInfo();
            }else if(orderType.equals(OrderType.RETURN_SHIP_FEE.getCode())){
                result = OrderType.RETURN_SHIP_FEE.getInfo();
            }else if(orderType.equals(OrderType.LNG_DELIVERY_FEE.getCode())){
                result = OrderType.LNG_DELIVERY_FEE.getInfo();
            }else if(orderType.equals(OrderType.LNG_RETURN_FEE.getCode())){
                result = OrderType.LNG_RETURN_FEE.getInfo();
            }else if(orderType.equals(OrderType.FUEL_DELIVERY_SETTLE.getCode())){
                result = OrderType.FUEL_DELIVERY_SETTLE.getInfo();
            }else if(orderType.equals(OrderType.FUEL_RETURN_SETTLE.getCode())){
                result = OrderType.FUEL_RETURN_SETTLE.getInfo();
            }
        }
        return result;
    }

    public String getOrderStatusStr(){
        String result = null;
        if (getOrderStatus()!=null) {
            if(orderStatus.equals(OrderStatus.UNAUDITE.getCode())){
                result = OrderStatus.UNAUDITE.getInfo();
            }else if(orderStatus.equals(OrderStatus.AUDITE.getCode())){
                result = OrderStatus.AUDITE.getInfo();
            }else if(orderStatus.equals(OrderStatus.PAID.getCode())){
                result = OrderStatus.PAID.getInfo();
            }
        }
        return result;
    }
}
